package com.yq.spbYq.mapper;

import com.yq.spbYq.WasteLog;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface WasteLogMapper {
    // 查询所有记录
    @Select("SELECT * FROM wastelog")
    @Results({
            @Result(property = "rId", column = "r_id"),
            @Result(property = "rName", column = "r_name"),
            @Result(property = "rPhone", column = "r_phone"),
            @Result(property = "rAddress", column = "r_address"),
            @Result(property = "userType", column = "user_type")
    })
    List<WasteLog> selectAllWasteLogs();

    // 根据ID查询记录
    @Select("SELECT * FROM wastelog WHERE r_id = #{rId}")
    @Results({
            @Result(property = "rId", column = "r_id"),
            @Result(property = "rName", column = "r_name"),
            @Result(property = "rPhone", column = "r_phone"),
            @Result(property = "rAddress", column = "r_address"),
            @Result(property = "userType", column = "user_type")
    })
    WasteLog selectWasteLogById(Integer rId);

    // 插入一条记录
    @Insert("INSERT INTO wastelog (r_name, r_phone, r_address, user_type) VALUES (#{rName}, #{rPhone}, #{rAddress}, #{userType})")
    @Options(useGeneratedKeys = true, keyProperty = "rId")
    int insertWasteLog(WasteLog wastelog);

    // 更新一条记录
    @Update("UPDATE wastelog SET r_name = #{rName}, r_phone = #{rPhone}, r_address = #{rAddress}, user_type = #{userType} WHERE r_id = #{rId}")
    int updateWasteLog(WasteLog wastelog);

    // 根据ID删除记录
    @Delete("DELETE FROM wastelog WHERE r_id = #{rId}")
    int deleteWasteLogById(Integer rId);
}